package com.sreader.sreader4j;

import java.util.Locale;

import com.vaadin.data.Validator;
import com.vaadin.event.FieldEvents.TextChangeEvent;
import com.vaadin.event.FieldEvents.TextChangeListener;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.AbstractTextField.TextChangeEventMode;
import com.vaadin.ui.Window;
import com.vaadin.data.validator.*;

public class IdentityComponentUI extends CustomComponent {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private GridLayout mainLayout;
	private TextField entry_14;
	private TextField entry_13;
	private TextField entry_12;
	private TextField entry_11;
	private TextField entry_10;
	private TextField entry_9;
	private TextField entry_8;
	private TextField entry_7;
	private TextField entry_6;
	private TextField entry_5;
	private TextField entry_4;
	private TextField entry_3;
	private TextField entry_2;
	private TextField entry_1;
	private TextField entry_0;
	private Validator letterEntryValidator;
	private Locale currentLocaleValue;
	private Window mainWindow;
	private Messages messages;

	

	

	
	/**
	 * The constructor should first build the main layout, set the
	 * composition root and then do any custom initialization.
	 *
	 * The constructor will not be automatically regenerated by the
	 * visual editor.
	 */
	public IdentityComponentUI(Locale defaultLocale,Window main) {
		mainWindow = main;
		setCurrentLocaleValue(defaultLocale);
		setMessages(new Messages("FeuilleDeCalcul",defaultLocale));
		buildMainLayout();
		setCompositionRoot(mainLayout);

		// TODO add user code here
	}


	private void setCurrentLocaleValue(Locale currentLocaleValue) {
		this.currentLocaleValue = currentLocaleValue;
	}
	
	public Messages getMessages() {
		return messages;
	}

	public void setMessages(Messages messages) {
		this.messages = messages;
	}
	
	private GridLayout buildMainLayout() {
		// common part: create layout
		mainLayout = new GridLayout();
		mainLayout.setStyleName("identityComponentGridStyle");
		mainLayout.setImmediate(true);
		mainLayout.setWidth("495.0px");
		mainLayout.setHeight("33px");
		mainLayout.setMargin(false);
		mainLayout.setColumns(15);
		
		// top-level component properties
		setWidth("495.0px");
		setHeight("34px");
		//letterEntryValidator
		letterEntryValidator = new RegexpValidator("[a-zA-ZäöüßÄÖÜ]", this.messages.getString("numericValidator")); 
		// entry_0
		entry_0 = new TextField();
		entry_0.setImmediate(true);
		entry_0.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_0.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					//entry_1.focus();
				}
			}
		});
		entry_0.addValidator(letterEntryValidator);
		entry_0.setWidth("32px");
		entry_0.setHeight("20px");
		entry_0.setTabIndex(0);
		entry_0.setMaxLength(1);
		
		mainLayout.addComponent(entry_0, 0, 0);
		
		// entry_1
		entry_1 = new TextField();
		entry_1.setImmediate(true);
		entry_1.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_1.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_2.focus();
				}
			}
		});
		entry_1.addValidator(letterEntryValidator);
		entry_1.setWidth("32px");
		entry_1.setHeight("20px");
		entry_1.setTabIndex(1);
		entry_1.setMaxLength(2);
		mainLayout.addComponent(entry_1, 1, 0);
		
		// entry_2
		entry_2 = new TextField();
		entry_2.setImmediate(true);
		entry_2.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_2.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_3.focus();
				}
			}
		});
		entry_2.addValidator(letterEntryValidator);
		entry_2.setWidth("32px");
		entry_2.setHeight("20px");
		entry_2.setTabIndex(2);
		entry_2.setMaxLength(1);

		mainLayout.addComponent(entry_2, 2, 0);
		
		// entry_3
		entry_3 = new TextField();
		entry_3.setImmediate(true);
		entry_3.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;


			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_4.focus();
				}
			}
		});
		entry_3.addValidator(letterEntryValidator);
		entry_3.setWidth("32px");
		entry_3.setHeight("20px");
		entry_3.setTabIndex(3);
		entry_3.setMaxLength(1);
		entry_3.setTextChangeEventMode(TextChangeEventMode.EAGER);
		
		mainLayout.addComponent(entry_3, 3, 0);
		
		// entry_4
		entry_4 = new TextField();
		entry_4.setImmediate(true);
		entry_4.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_4.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_5.focus();
				}
			}
		});
		entry_4.addValidator(letterEntryValidator);
		entry_4.setWidth("32px");
		entry_4.setHeight("20px");
		entry_4.setTabIndex(4);
		entry_4.setMaxLength(1);
		
		
		mainLayout.addComponent(entry_4, 4, 0);
		
		// entry_5
		entry_5 = new TextField();
		entry_5.setImmediate(true);
		entry_5.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_5.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_6.focus();
				}
			}
		});
		entry_5.addValidator(letterEntryValidator);
		entry_5.setWidth("32px");
		entry_5.setHeight("20px");
		entry_5.setTabIndex(5);
		entry_5.setMaxLength(1);
		
		mainLayout.addComponent(entry_5, 5, 0);
		
		// entry_6
		entry_6 = new TextField();
		entry_6.setImmediate(true);
		entry_6.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_6.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_7.focus();
				}
			}
		});
		entry_6.addValidator(letterEntryValidator);
		entry_6.setWidth("32px");
		entry_6.setHeight("20px");
		entry_6.setMaxLength(1);
		entry_6.setTabIndex(6);
		
		mainLayout.addComponent(entry_6, 6, 0);
		
		// entry_7
		entry_7 = new TextField();
		entry_7.setImmediate(true);
		entry_7.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_7.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_8.focus();
				}
			}
		});
		entry_7.addValidator(letterEntryValidator);
		entry_7.setWidth("32px");
		entry_7.setHeight("20px");
		entry_7.setTabIndex(7);
		entry_7.setMaxLength(1);

		mainLayout.addComponent(entry_7, 7, 0);
		
		// entry_8
		entry_8 = new TextField();
		entry_8.setImmediate(true);
		entry_8.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_8.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_9.focus();
				}
			}
		});
		entry_8.addValidator(letterEntryValidator);
		entry_8.setWidth("32px");
		entry_8.setHeight("20px");
		entry_8.setTabIndex(8);
		entry_8.setMaxLength(1);

		mainLayout.addComponent(entry_8, 8, 0);
		
		// entry_9
		entry_9 = new TextField();
		entry_9.setImmediate(true);
		entry_9.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_9.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_10.focus();
				}
			}
		});
		entry_9.addValidator(letterEntryValidator);
		entry_9.setWidth("32px");
		entry_9.setHeight("20px");
		entry_9.setTabIndex(9);
		entry_9.setMaxLength(1);

		mainLayout.addComponent(entry_9, 9, 0);
		
		// entry_10
		entry_10 = new TextField();
		entry_10.setImmediate(true);
		entry_10.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_10.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_11.focus();
				}
			}
		});
		entry_10.addValidator(letterEntryValidator);
		entry_10.setWidth("32px");
		entry_10.setHeight("20px");
		entry_10.setTabIndex(10);
		entry_10.setMaxLength(1);

		mainLayout.addComponent(entry_10, 10, 0);
		
		// entry_11
		entry_11 = new TextField();
		entry_11.setImmediate(true);
		entry_11.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_11.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_12.focus();
				}
			}
		});
		entry_11.addValidator(letterEntryValidator);
		entry_11.setWidth("32px");
		entry_11.setHeight("20px");
		entry_11.setTabIndex(11);
		entry_11.setMaxLength(1);

		mainLayout.addComponent(entry_11, 11, 0);
		
		// entry_12
		entry_12 = new TextField();
		entry_12.setImmediate(true);
		entry_12.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_12.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_13.focus();
				}
			}
		});
		entry_12.addValidator(letterEntryValidator);
		entry_12.setWidth("32px");
		entry_12.setHeight("20px");
		entry_12.setTabIndex(12);
		entry_12.setMaxLength(1);

		mainLayout.addComponent(entry_12, 12, 0);
		
		// entry_13
		entry_13 = new TextField();
		entry_13.setImmediate(true);
		entry_13.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_13.addListener(new TextChangeListener() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public void textChange(TextChangeEvent event) {
				// TODO Auto-generated method stub
				if(event.getText().length()>0){
					entry_14.focus();
				}
			}
		});
		entry_13.addValidator(letterEntryValidator);
		entry_13.setWidth("32px");
		entry_13.setHeight("20px");
		entry_13.setTabIndex(13);
		entry_13.setMaxLength(1);

		mainLayout.addComponent(entry_13, 13, 0);
		
		// entry_14
		entry_14 = new TextField();
		entry_14.setImmediate(true);
		entry_14.setWidth("32px");
		entry_14.setHeight("20px");
		entry_14.setTabIndex(14);
		entry_14.setMaxLength(1);
		entry_14.setTextChangeEventMode(TextChangeEventMode.EAGER);
		entry_14.addValidator(letterEntryValidator);
		mainLayout.addComponent(entry_14, 14, 0);
		
		return mainLayout;
	}

}
